<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>TodoList</title>
    <%@ include file="/pages/common/header.jsp" %>
    <script type="text/javascript">
        $(function () {
            $("#search-button").click(function () {
                location.href = "ClientServlet?action=pageTasknameBlurByUserId&taskname=" + $("#search-input").val();
                return false;
            });

            $("#create-button").click(function () {
                location.href = "TaskServlet?action=addRedirect";
                return false;
            });
        });
    </script>
</head>
<body>
<div class="info">
    <span class="displayedUsername">${sessionScope.user.username}</span>
    <a href="UserServlet?action=logout" class="exit">退出登录</a>
    <a href="ManagerUserServlet?action=page&pn=1" class="manager">后台管理</a>
</div>
<h1>我的代办任务</h1>
<div class="greetings">Enjoy your coder life.</div>
<table id="content">
    <tr id="search-box">
        <td colspan="3"><input type="text" name="search" placeholder="输入任务关键词（支持模糊搜索）" id="search-input"
                               style="width: 200px;">
            <input type="button" value="搜索" name="search" id="search-button" style="margin-left: 10px"></td>
        <td></td>
        <td></td>
        <td><input type="button" value="新建" name="create" id="create-button"></td>
    </tr>
    <tr>
        <th>编号</th>
        <th>任务名称</th>
        <th>任务状态</th>
        <th>更新时间</th>
        <th>创建时间</th>
        <th>操作</th>
    </tr>
    <c:forEach items="${page.pes}" var="task">
        <tr>
            <td class="id">${task.id}</td>
            <td class="taskname">${task.taskname}</td>
            <td class="status">${task.status == 0 ? "未完成": "已完成"}</td>
            <td class="time_update">${task.timeUpdate}</td>
            <td class="time_create">${task.timeCreate}</td>
            <td class="action">
                <button class="edit" onclick="location.href = 'TaskServlet?action=queryTask&id=${task.id}&pn=${page.pn}'">编辑</button>
                <button class="delete" onclick="location.href='TaskServlet?action=delete&id=${task.id}'">删除</button>
            </td>
        </tr>
    </c:forEach>
</table>
<%@ include file="/pages/common/page_nav.jsp" %>
</body>
</html>